#!/usr/bin/env node

const args = process.argv.slice(2);

function showHelp() {
  console.log('使用方法:');
  console.log('  node calc.js [数学表达式]');
  console.log('示例:');
  console.log('  node calc.js "2 + 3 * 4"');
}

if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
  showHelp();
  process.exit(0);
}

const expression = args.slice(0, 3).join(' ');

try {
  const result = eval(expression);
  console.log(`计算结果: ${result}`);
} catch (error) {
  console.error('错误: 无效的数学表达式');
  showHelp();
  process.exit(1);
}